import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

import path from 'path'

// https://vitejs.dev/config/
export default defineConfig({
  /**
   * 与“根”相关的目录，构建输出将放在其中。如果目录存在，它将在构建之前被删除。
   * @default 'dist'
   */
  outDir: 'target',
  // 是否自动在浏览器打开
  open: true,
  // 是否开启 https
  https: false,
  // 服务端渲染
  ssr: false,
  alias : {
    "@" :path.resolve(__dirname, "src"),
    "comps" :path.resolve(__dirname, "src/components"),
    "apis" :path.resolve(__dirname, "src/apis"),
    "assets" :path.resolve(__dirname, "src/assets"),
    "views" :path.resolve(__dirname, "src/views"),
    "utils" :path.resolve(__dirname, "src/utils"),
    "routes" :path.resolve(__dirname, "src/routes"),
    "styles" :path.resolve(__dirname, "src/styles"),
    "store" :path.resolve(__dirname, "src/store"),
    "plugins" :path.resolve(__dirname, "src/assets/plugins"),
  },
  plugins: [vue()],
  // 反向代理
  server: {
    proxy: {
      // 字符串简写写法
      '/foo': 'http://localhost:4567/foo',
      // 选项写法
      '/api': {
        target: 'http://localhost:9090',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '')
      },
      // 正则表达式写法
      '^/fallback/.*': {
        target: 'http://jsonplaceholder.typicode.com',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/fallback/, '')
      }
    }
  }
})
